package io;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import com.thoughtworks.xstream.XStream;
import datamodel.Grid;

public class SudokuReader {

	public static Grid read(String path) {
		String content = readFile(path);
		XStream stream = XStreamFactory.getXStream();
		Grid g = (Grid) stream.fromXML(content);
		return g;
	}

	private static String readFile(String path) {
		FileReader reader = null;
		BufferedReader br = null;
		String content = new String();
		String line = new String();
		try {
			reader = new FileReader(path);
			br = new BufferedReader(reader);
			content = new String();
			while ((line = br.readLine()) != null) {
				content = content.concat(line);
			}
		} catch (IOException e) {
			System.err.println("Fehler beim Lesen der Datei!");
		} finally {
			try {
				reader.close();
				br.close();
			} catch (Exception e) {
			}
		}
		return content;
	}
}
